// src/utils/MonitorService.js
export default class MonitorService {
  constructor() {
    this.devicesStatus = {
      '服务器1': 'normal',
      '服务器2': 'normal',
      '交换机1': 'normal',
      '交换机2': 'normal',
      '路由器1': 'normal',
      '路由器2': 'normal'
    };

    this.linksStatus = {
      '服务器1-交换机1': { usage: 50, status: 'normal' },
      '服务器2-交换机2': { usage: 60, status: 'normal' },
      '交换机1-路由器1': { usage: 70, status: 'normal' },
      '交换机2-路由器2': { usage: 80, status: 'normal' }
    };
  }

  // 模拟更新设备状态
  updateDeviceStatus(deviceName, status) {
    this.devicesStatus[deviceName] = status;
  }

  // 模拟更新链路状态
  updateLinkStatus(source, target, usage, status) {
    this.linksStatus[`${source}-${target}`] = { usage, status };
  }

  // 获取实时监控数据
  getRealTimeData() {
    return {
      devices: Object.entries(this.devicesStatus).map(([name, status]) => ({
        name,
        status
      })),
      links: Object.entries(this.linksStatus).map(([key, { usage, status }]) => ({
        source: key.split('-')[0],
        target: key.split('-')[1],
        usage,
        status
      }))
    };
  }
}
